# encoding: utf-8
# @Author: zsl
# @Desc : 重量转换器
# 重量换算是指单位值乘以标准换算值，使用Python中的Tkinter库创建一个重量转换器应用程序
# @Date  : 2025/07/09 10:21
def convert_weight(value, from_unit, to_unit):
    units = {
        "gram": 1,
        "kilogram": 1000,
        "pound": 453.592,
        "ounce": 28.3495
    }
    if from_unit not in units or to_unit not in units:
        return "Invalid units"
    return value * units[from_unit] / units[to_unit]

# 示例用法
weight = 100
print(f"{weight} grams is {convert_weight(weight, 'gram', 'kilogram')} kilograms.")
print(f"{weight} grams is {convert_weight(weight, 'gram', 'pound')} pounds.")
print(f"{weight} grams is {convert_weight(weight, 'gram', 'ounce')} ounces.")

